function useCopyToClipboard(): [boolean, (val: string) => Promise<void>] {
  const [isCopied, setIsCopied] = useState(false)

  const copyToClipboard = async (text: string) => {
    try {
      await navigator.clipboard.writeText(text)
      setIsCopied(true)
      setTimeout(() => {
        setIsCopied(false)
      }, 2000) // 2秒后重置复制状态
    } catch (error) {
      console.error('Failed to copy text: ', error)
    }
  }

  return [isCopied, copyToClipboard]
}

export default useCopyToClipboard
